﻿@{
    ViewBag.Title = "Index";
    Layout = "~/Views/Shared/_ContentLayout.cshtml";
} 
@section HeadIncluder 
{
    <link href='@Url.Content("~/Content/public.css")'  type="text/css" rel="stylesheet" />
    <link href='@Url.Content("~/Content/con_style.css")'  type="text/css" rel="stylesheet" />
    <link rel="stylesheet" type="text/css" href=@Url.Content("~/Scripts/skins/default.css")   />
    <script type="text/javascript"  src=@Url.Content("~/Scripts/lhgdialog.min.js") ></script>
}
<div class="content" onkeydown="EnterClick(event.keyCode)">
    <div class="ss_box list_tble" style="margin-top: 20px;">
        <div class="s_box1">
            <table class="s_tble ">
                <tr>
                    <td   class="aR">流程标题/序号:</td>
                    <td class="aL" colspan="2">
                        <input id="txtAppName" type="text" name="AppName" /></td>
                    <td  class="aR">单据类型:</td>
                    <td class="aL" colspan="2"  >
                        <select id="dpProcessList" name="ProcessList">
                            <option value="" selected="selected">全部</option>
                            @{
                                IList<FCDB.Entity.WfProcess> list = ViewBag.ProcessList as IList<FCDB.Entity.WfProcess>;
                                foreach (var item in list)
                                {
                                <option value="@item.ProcessGUID"   >@item.ProcessName</option>
                                }
                            }
                        </select>
                    </td>
                    <td  class="aR">发送时间:</td>
                    <td class="aL">
                        <input id="txtStartDate" type="text" />到<input id="txtEndDate" type="text" />
                    </td>
                    
                </tr>
                <tr>
                     <td class="aR">创建人:</td>
                    <td class="aL" > 
                        <input id="txtUsersName" type="text" name="UsersName" disabled="disabled"  style="width:120px;" />
                        <input type="hidden" id="txtUsersID" name="txtUsersID" />
                    </td>
                    <td class="aL"><span class="btn_s btn_c1"><a href="javascript:void(0)" onclick="addUsers()">添加</a></span></td>
                    <td class="aR">创建部门:</td> 
                    <td class="aL">
                        <input id="txtUsersDepartment" type="text" name="UsersDepartment" disabled="disabled"  style="width:120px;" />
                        <input type="hidden" id="txUsersDepartmentID" name="txtUsersDepartmentID" />
                    </td>
                    <td><span class="btn_s btn_c1"  >
                            <a href="javascript:void(0)" onclick="SelectDeparment(txUsersDepartmentID,txtUsersDepartment)">选择部门</a></span></td>
                    <td class="aL"   colspan="2"><span class="btn_s btn_c1" style="margin-left: 4px;"><a href="javascript:void(0)" onclick="onRefresh()">查找</a></span></td>
                </tr>
            </table>
        </div>
    </div>
</div>
<div id="container" style="margin-right: 10px;"> 
    <div id="grid" style="width: 100%; height: 100%;">
    </div> 
</div>
<script type="text/javascript" >
    function ReverseProcess(e) {
        e.preventDefault();
        var row = this.dataItem($(e.currentTarget).closest("tr"));
        var AppInstanceID = row.AppInstanceID;
        var AppName = row.AppName;
        var ProcessGUID = row.ProcessGUID;
        var url = '@Url.Action("ReverseProcess")';
        $.post(url, { AppInstanceID: AppInstanceID, AppName: AppName, ProcessGUID: ProcessGUID }, function (data) {
            alert(data);
            onRefresh();
        }); 
    }
    function CancelProcess(e) {
        e.preventDefault();
        var row = this.dataItem($(e.currentTarget).closest("tr"));
        var AppInstanceID = row.AppInstanceID;
        var AppName = row.AppName;
        var ProcessGUID = row.ProcessGUID;
        var url = '@Url.Action("CancelProcess")';
        $.post(url, { AppInstanceID: AppInstanceID, AppName: AppName, ProcessGUID: ProcessGUID }, function (data) {
            alert(data);
            onRefresh();
        }); 
    }
    function EnterClick(va) {
        if (va == 13) {
            onRefresh()
        }
    }
    function ShowDetail(e) {
        e.preventDefault();
        var row = this.dataItem($(e.currentTarget).closest("tr"));
        var AppInstanceID = row.AppInstanceID;
        var AppName = row.AppName;
        var ProcessGUID = row.ProcessGUID;
        var url = '@Url.Action("ViewProccessInstance","ProcessQuery")' + "?AppInstanceID=" + AppInstanceID + "&&AppName=" + AppName + "&&ProcessGUID=" + ProcessGUID;
        var width = screen.availWidth * 0.8;
        var top = screen.availWidth * 0.05;
        var left = screen.availWidth * 0.1;
        var height = screen.availHeight * 0.8;
         window.open(url, "", "width=" + width + "px, height=" + height + "px, top=" + top + "px, left=" + left + "px");
    }
     function onClear() {
         $("#frm").reset();
     }
 
      function SelectDeparment(valtag, textTag) {
          var url = '@Url.Action("UCDepartmentSelect", "Form")';
        window.top.winObj = window;
        window.top.refresh = function (vals, txts) {
            $(valtag).val(vals);
            $(textTag).val(txts);
        };
        window.top.oDG = $.dialog({
            lock: true,
            background: '#FFF',
            opacity: 0.5,
            id: 'esDialog',
            title: '部门选择',
            titleAlign: 'left',
            content: "url:" + url,
            width: 570,
            height: 300,
            btnBar: false,
            lockScroll: true
        });
    }
     function onRefresh() {
         var grid = $("#grid").data("kendoGrid");
         grid.dataSource.read();
     }
 
     function addUsers() {
         var url = '@Url.Action("EmployeeSelect", "Employee")';
         OpenSelectUserPop(url, function (selectPostList) {
             if (selectPostList != null || selectPostList != undefined) {
                 var strNames = "";
                 var strUserIDs = "";
                 $.each(selectPostList, function (i, val) {
                     strNames += val.Name + ";";
                     strUserIDs += val.UserID + ";";
                     $("#txtUsersName").val(strNames);
                     $("#txtUsersID").val(strUserIDs);
                 });
             }
         }); 
     } 
     function loadData() {
         $("#grid").kendoGrid({
             selectable: "multiple,row",
             dataSource: {
                 serverPaging: true,
                 pageSize: 10,
                 transport: {
                     read: {
                         url: '@Url.Action("Index")',
                         type: "POST",
                         dataType: "json",
                         data: {
                             dtStart: function () {
                                 return $("#txtStartDate").val();
                             },
                             dtEnd: function () {
                                 return $("#txtEndDate").val();
                             },
                             keyword: function () {
                                 return $("#txtAppName").val();
                             },
                             UserIDs: function () {
                                 return $("#txtUsersID").val();
                             },
                             DeparmentID: function () {
                                 return $("#txUsersDepartmentID").val();
                             },
                             ProcessGUID: function () {
                                 return $("#dpProcessList").val();
                             }
                         }
                     }
                 },
                 schema: {
                     //取出資料陣列
                     model: {
                         fields: {
                             CreatedDateTime: { type: "date" }
                         }
                     },
                     data: function (d) { return d.Data; },
                     //取出資料總筆數(計算頁數用)
                     total: function (d) { return d.TotalCount; }
                 }
             },
             height: 600,
           
             pageable: {
                 refresh: true,
                 pageSizes: true
             },
             dataBinding: function (e) {
                 for (var i = 0; i < e.items.length; i++) {
                     switch (e.items[i].ProcessState) {
                         case 0:
                             e.items[i].ProcessState = "未启动";
                             break;
                         case 1:
                             e.items[i].ProcessState = "准备";
                             break;
                         case 2:
                             e.items[i].ProcessState = "流转中";
                             break;
                         case 4:
                             e.items[i].ProcessState = "结束";
                             break;
                         case 8:
                             e.items[i].ProcessState = "挂起";
                             break;
                         case 16:
                             e.items[i].ProcessState = "取消";
                             break;
                         case 32:
                             e.items[i].ProcessState = "终止";
                             break;

                     }

                 }
             },
             columns: [
                     { field: "AppInstanceID", title: "序号" },
                     { field: "ProcessName", title: "流程名称" },
                     { field: "AppName", title: "流程实例名称" },
                     { field: "ProcessState", title: "流程状态" },
                     { field: "ActivityName", title: "当前步骤" },
                     { field: "SendUserName", title: "发送人" },
                     { field: "CreatedDateTime", title: "创建时间", format: "{0:yyyy-MM-dd }" },
                     { field: "ProcessGUID", title: "ProcessGUID", hidden: true },
                     { command: { text: "返签", click: ReverseProcess }, title: "返回", width: "80px;" },
                     { command: { text: "撤销", click: CancelProcess }, title: "撤销", width: "80px;" },
                     { command: { text: "查看", click: ShowDetail }, title: "查看", width: "80px;" }
             ]
         });
     }

     $(function () {
         loadData();
         $("#txtStartDate").kendoDatePicker({ format: "yyyy-MM-dd" });
         $("#txtEndDate").kendoDatePicker({ format: "yyyy-MM-dd" });
     });
 </script>
